'use strict';

const {
  DataTypes,
} = require('sequelize');

module.exports = app => {
  const { STRING, INTEGER, DATE, UUIDV4, UUID, UUIDV1 } = app.Sequelize;

  const attributes = {
      name: {
        type: STRING(30),
        allowNull: true,
        defaultValue: null,
        primaryKey: false,
        autoIncrement: false,
        comment: null,
        field: 'name',
      },
      id_name: {
        type: STRING(18),
        allowNull: false,
        comment:'证件号'
      },
      password: {
        type: STRING,
        comment: '密码'
      },
      age: {
        type: STRING(3),
        comment: '年龄',
        allowNull: true,
      },
      gender: {
        type: STRING(1),
        defaultValue: 'F',
        comment: '性别',
        allowNull: true,
      },
      province_code: {
        type: STRING(8),
        allowNull: true,
        comment: '省-code'
      },
      city_code: {
        type: STRING(8),
        allowNull: true,
        comment: '市-code'
      },
      county_code: {
        type: STRING(8),
        allowNull: true,
        comment: '区-code'
      },
      address: {
        type: STRING(128),
        allowNull: true,
        comment: '地址'
      },
      uuid: {
        type: UUID,
        defaultValue: UUIDV4,
        allowNull: false,
        primaryKey: true
      },
      created_at: {
        type: DATE,
        allowNull: true,
        defaultValue: null,
        primaryKey: false,
        autoIncrement: false,
        comment: null,
        field: 'created_at',
      },
      updated_at: {
        type: DATE,
        allowNull: true,
        defaultValue: null,
        primaryKey: false,
        autoIncrement: false,
        comment: null,
        field: 'updated_at',
      },
  };
  const options = { 
    tableName: 'users',
    comment: '通过sequelize-automate自动生成的model修改之后得到',
    indexes: [],
  };
  const UsersModel = app.model.define('users_model', attributes, options);
  return UsersModel;
};

/*
//  原始代码，现在使用sequelize-automate生成的代码修改
'use strict';

module.exports = app => {
  const { STRING, INTEGER, DATE } = app.Sequelize;

  const Users = app.model.define( 'users', {
    id: { type: INTEGER, primaryKey: true, autoIncreament: true },
    name: STRING(30),
    age: INTEGER,
    created_at: DATE,
    updated_at: DATE
  })

  return Users;
}

  // 初始化  users表
  // npx sequelize migration:generate --name=init-users

  // 执行进行数据库变更
  // npx sequelize db:migrate

 */
